package com.im323.application;

import java.util.List;

import com.im323.dnspod.DnsPodErrorEnum;
import com.im323.dnspod.DnspodService;
import com.im323.dnspod.result.DnspodRecord;
import com.im323.dnspod.result.DnspodRecordLine;
import com.im323.dnspod.result.DnspodResult;

public class IMDDNSRecordController {

	public static List<DnspodRecord> getRecondList(Integer domainId) {
		if (domainId == null) {
			System.out.println("数据参数错误");
			return null;
		}
		DnspodResult<List<DnspodRecord>> dnspodResult = DnspodService.getRecordList(domainId);
		if (dnspodResult.getStatus().getCode() != DnsPodErrorEnum.SUCCESS.getCode()) {
			System.out.println(dnspodResult.getStatus().getMessage());
			return null;
		}

		return dnspodResult.getInfo();
	}

	/**
	 * 初始化记录类型数据源
	 * 
	 * @return
	 */
	public static List<String> getTypeDataList(String userGrade) {
		DnspodResult<List<String>> dnspodResult = DnspodService.getRecordType(userGrade);
		if (dnspodResult.getStatus().getCode() != DnsPodErrorEnum.SUCCESS.getCode()) {
			System.out.println(dnspodResult.getStatus().getMessage());
			return null;
		}
		return dnspodResult.getInfo();
	}

	/** 初始化线路数据源 */
	public static List<DnspodRecordLine> getLineDataList(Integer domainId, String userGrade) {
		DnspodResult<List<DnspodRecordLine>> dnspodResult = DnspodService.getRecordLine(domainId, userGrade);
		if (dnspodResult.getStatus().getCode() != DnsPodErrorEnum.SUCCESS.getCode()) {
			System.out.println(dnspodResult.getStatus().getMessage());
			return null;
		}
		return dnspodResult.getInfo();
	}

	/**
	 * 获取记录详情
	 * 
	 * @param domainId
	 * @param recordId
	 * @return
	 */
	public static DnspodRecord getRecordInfo(Integer domainId, Integer recordId) {
		DnspodResult<DnspodRecord> dnspodResult = DnspodService.getRecordInfo(domainId, recordId);
		if (dnspodResult.getStatus().getCode() != DnsPodErrorEnum.SUCCESS.getCode()) {
			System.out.println(dnspodResult.getStatus().getMessage());
			return null;
		}
		return dnspodResult.getInfo();
	}

}
